package cn.com.wdjedu.androidapp.wjeduandroid.ui.mainfragment;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.Constanct;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.baseui.ListAdapter;

/**
 * Created by CCY on 2017/2/15.
 */

public class ClassflyItemAdapter extends ListAdapter<MainBean.TypesBean> {


    public ClassflyItemAdapter(Context context, List<MainBean.TypesBean> datasource) {
        super(context, datasource);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_main_tab_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MainBean.TypesBean bean = getItem(position);
        viewHolder.tabText.setText(bean.getName());
        ImageLoader.getInstance().displayImage(Constanct.IMAGE_URL2 + bean.getPicture_path(), viewHolder.tabImage);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tab_image)
        ImageView tabImage;
        @BindView(R.id.tab_text)
        TextView tabText;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
